package cn.csdj.sism.service.impl;

import cn.csdj.sism.dao.ClassMapper;
import cn.csdj.sism.pojo.ObtainEmployment;
import cn.csdj.sism.pojo.Student;
import cn.csdj.sism.service.ClassService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import cn.csdj.sism.pojo.Class;
import org.springframework.util.StringUtils;

import java.util.HashMap;
import java.util.List;

@Service
public class ClassServiceImpl implements ClassService {

    @Autowired
    private ClassMapper classMapper;

    @Override
    public int insert(Class aClass) {
        return classMapper.insert(aClass);
    }

    @Override
    public int deleteById(Integer id) {
        return classMapper.deleteById(id);
    }

    @Override
    public int update(Class aClass) {
        return classMapper.updateById(aClass);
    }

    @Override
    public Class selectById(Integer id) {
        return classMapper.selectById(id);
    }

    @Override
    public List<Class> selectAll() {
        return classMapper.selectList(null);
    }
    /**
     * 分页查询
     *
     * @param current 当前页码
     * @return
     */
    @Override
    public IPage<Class> selectPages(Integer current, Integer pageSize) {
//        Page(当前页码，页面大小);
            IPage<Class> page = new Page(current,pageSize);
            classMapper.selectPage(page,null);
            return page;//返回数据

    }

    @Override
    public IPage<Class> selectPagesByHeBan(HashMap heban) {
        IPage<Class> page=new Page<>((Integer) heban.get("current"),(Integer) heban.get("pageSize"));
        LambdaQueryWrapper<Class> lqw = new LambdaQueryWrapper<>();
        if (!StringUtils.isEmpty(heban.get("className"))){
            lqw.like(Class::getClassName,heban.get("className"));
        }
        if (!StringUtils.isEmpty(heban.get("clsStatus"))){
            lqw.eq(Class::getClsStatus,heban.get("clsStatus"));
        }
        classMapper.selectPage(page,lqw);
        return page;
    }

}
